const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    keyWord: '',
    prov: '',
    provname: '',
    city: '',
    cityname: '',
    type: 1,
    provnamecname: '',
    id: -1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      type: options.type
    })
    if (options.type == 1 && options.isgai == 1) {
      var key = wx.getStorageSync('zcdykey');
      this.setData({
        keyWord: key.keyWord,
        id: key.ID,
        provname: key.pcname,
        prov: key.pcids,
        provnamecname: key.pcname
      })
    }
    if (options.type == 2 && options.isgai == 1) {
      var key = wx.getStorageSync('zcdykey');
      this.setData({
        keyWord: key.keyWord,
        id: key.ID,
        provname: key.provname,
        prov: key.prov,
        provnamecname: key.provname,
        city: key.city,
        cityname: key.cityname
      })
    }
    if (options.type == 3 && options.isgai == 1) {
      var key = wx.getStorageSync('zcdykey');
      this.setData({
        keyWord: key.keyWord,
        id: key.ID,
        provname: key.provname,
        prov: key.prov,
        provnamecname: key.provname
      })
    }
  },
  keyInput: function (e) {
    this.setData({
      keyWord: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {


  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  selectAddr: function () {
    var that = this;
    if (this.data.keyWord.length < 1) {
      app.tishi('请先填写关键字!'); return false;
    }
    wx.navigateTo({
      url: 'selectprovince?type=' + that.data.type
    })
  },
  addkey: function () {
    var that = this;
    var FjLoginLog = wx.getStorageSync('FjLoginLog');
    if (this.data.id == -1) {
      var api_input = {
        type: this.data.type,
        keyWord: this.data.keyWord,
        prov: this.data.prov,
        provname: this.data.provname,
        city: this.data.city,
        cityname: this.data.cityname,
        uid: FjLoginLog.UID,
        platform_type: 4
      }
      var url = 'api/FeijiuApp/Post_FJ_AddDingYue';
    } else {
      var api_input = {
        type: this.data.type,
        keyWord: this.data.keyWord,
        prov: this.data.prov,
        provname: this.data.provname,
        city: this.data.city,
        cityname: this.data.cityname,
        uid: FjLoginLog.UID,
        ID: this.data.id,
        companyname: '',
        platform_type: 4
      }
      var url = 'api/FeijiuApp/Post_FJ_UpdateDingYue';
    }

    app.getDaoPostN(url, api_input, function (r) {

      if (r.code == 200) {
        if (that.data.id == -1) {
          app.tishi('添加成功');
        } else {
          app.tishi('修改成功');
        }

        var pages = getCurrentPages();
        var prevPage = pages[pages.length - 2];
        if (that.data.type == 3) {
          prevPage.getFeijiu_Get_BjDyKeyList();
        } else {
          prevPage.getKeyList();
        }
        setTimeout(function () {
          wx.navigateBack({
            delta: 1,
          })
        }, 1000)
      } else {
        if (that.data.id == -1) {
          app.tishi('添加失败');
        } else {
          app.tishi('修改失败');
        }
      }
    })
  }


})